package serv

import (
	"gorm.io/gorm"
	"server/internal/app/model"
	"server/internal/database"
)

var SystemLog = new(systemLog)

type systemLog struct {
	model.SystemLog
}

// Reads 列表
func (a systemLog) Reads(Db *gorm.DB) (*gorm.DB, []systemLog, int64) {
	var list []systemLog
	var total int64
	Db.Model(&a).
		Select("system_log.*,user.name,user.mobile").
		Joins("left join user on user.id = system_log.user_id").
		Order("id desc").Find(&list).Offset(-1).Count(&total)
	return Db, list, total
}

// Read 单条
func (a systemLog) Read(id any) (*gorm.DB, systemLog) {
	Db := database.DB
	detail := systemLog{}
	Db.Model(&a).Where("id =?", id).First(&detail)
	return Db, detail

}
